// HC-SR04 Using gpiod
#ifndef DEF_SONAR
#define DEF_SONAR
#include <chrono>

using namespace std;
class HCSR04
{
  public:
    HCSR04();
    ~HCSR04();
    void init(int trigger, int echo);
    double distance(int timeout);

  private:
    void recordPulseLength();
    int trigger;
    int echo;
    struct gpiod_chip *chip;
    struct gpiod_line *trigger_line;
    struct gpiod_line *echo_line;
    chrono::time_point<chrono::system_clock> startTimeUsec;
    chrono::time_point<chrono::system_clock> endTimeUsec;
    double distanceMeters;
 
};

#endif
